/**
 * @ClassName LC2864
 * 最大二进制数
 * @Author ykx
 * @Date 2024/3/13 16:46
 * @Version 1.0
 */
public class LC2864 {
    public static void main(String[] args) {
        LC2864 lc2864 = new LC2864();
        System.out.println(lc2864.maximumOddBinaryNumber("0101"));
    }

    public String maximumOddBinaryNumber(String s) {
        StringBuilder result = new StringBuilder("1");
        for (int i = 0; i < s.length(); i++) {
            switch (s.charAt(i)) {
                case '0':
                    result.insert(result.length() - 1, "0");
                    break;
                case '1':
                    if (i == s.lastIndexOf('1')) {
                        continue;
                    } else {
                        result.insert(0, "1");
                    }
                    break;
            }
        }

        return result.toString();
    }
}
